package com.net.shop.car.manager.ui.area;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import com.net.shop.car.manager.R;
import com.net.shop.car.manager.api.model.Area;
import com.net.shop.car.manager.ui.adapter.ProvinceAdapter;

public class AreaList {
	/**
	 * 
	 */
	private LayoutInflater inflater;
	
	private Context context;

	private ListView mLvProvince;
	private List<Area> provinceList;
	
	private View mView;
	
	private ViewGroup mParent;

	/**
	 * @param inflater
	 * @param context
	 * @param parent
	 */
	public AreaList(LayoutInflater inflater, Context context,ViewGroup parent) {
		this.inflater = inflater;
		this.context = context;
		this.mParent = parent;
		initViews();
	}
	
	private void initViews() {
		
		mView = inflater.inflate(R.layout.listview, mParent,false);
		mView.setBackgroundColor(context.getResources().getColor(R.color.TextColorWhite));
		mLvProvince = (ListView) mView;
		provinceList = new ArrayList<Area>();
		
		mParent.addView(mView);
//		mLvProvince.setOnItemClickListener(new OnItemClickListener() {
//
//			@Override
//			public void onItemClick(AdapterView<?> arg0, View arg1, int postion, long arg3) {
//				// TODO Auto-generated method stub
//				Bundle bundle = new Bundle();
//				bundle.putString("provinceid", provinceList.get(postion).getId());
//				bundle.putString("provincename", provinceList.get(postion).getName());
////				actionStart(CityCheckActivity.class, bundle);
////				ActivityCollector.addActivity(ProvinceChooseActivity.this);
//			}
//		});
		
//		initData();
	}
	
	public void setOnItemClickListener(OnItemClickListener itemClickListener) {
		mLvProvince.setOnItemClickListener(itemClickListener);
	}
	
	/**
	 * @return View
	 */
	public View getView() {
		return mView;
	}
	
	/**
	 * @param areList List<ProvinceModel>
	 */
	public void setData(List<Area> areList) {
		provinceList = areList;
		ProvinceAdapter adapter = new ProvinceAdapter(context, provinceList);
		mLvProvince.setAdapter(adapter);
	}

//	public void initData() {
//		// TODO Auto-generated method stub
//		VolleyCenter.getVolley().addPostRequest(new Province(), new VolleyListenerImpl<ProvinceResponse>(new ProvinceResponse()) {
//
//			@Override
//			public void deleveryResponse(ProvinceResponse response) {
//				if (response.isSuccess()) {
//					provinceList.clear();
//					provinceList.addAll(response.getProvince());
//					ProvinceAdapter adapter = new ProvinceAdapter(context, provinceList);
//					mLvProvince.setAdapter(adapter);
//				} else {
////					showToast(response.getErrorMsg());
//				}
//			}
//		});
//	}
}
